﻿function RealSearchContact() {
    RequireLookUp = document.getElementById("divRequireLookUp").value;
    ReturnCodeId = document.getElementById("divReturnCodeId").value;
    ReturnNameId = document.getElementById("divReturnNameId").value;

    Name = document.getElementById("divSearchCustomerName").value;
    Address = document.getElementById("divSearchCustomerAddress").value;
    Email = document.getElementById("divSearchCustomerEmail").value;
    Phone = document.getElementById("divSearchCustomerPhone").value;
    Agency = document.getElementById("divCheckAgency").checked.toString(); ;
    Applicant = document.getElementById("divCheckApplicant").checked.toString();
    Client = document.getElementById("divCheckClient").checked.toString();
    ThirdParty = document.getElementById("divCheckThirdParty").checked.toString();
    GE = document.getElementById("divCheckGE").checked.toString();
    Legal = document.getElementById("divCheckLegal").checked.toString();
    IP = document.getElementById("divCheckIP").checked.toString();
    PJ = document.getElementById("divCheckPJ").checked.toString();
    ContactName = document.getElementById("divSearchContactName").value;
    CountryIndex = document.getElementById("divSearchCountryIndex").value;
    ShortName = document.getElementById("divSearchShortName").value;
    CustomerTypeIndex = document.getElementById("divSearchCustomerTypeIndex").value;
    SearchLevel = document.getElementById("divSearchLevel").selectedIndex.toString();
    fromDate = document.getElementById("divSearchCustomerFromDate").value;
    toDate = document.getElementById("divSearchCustomerToDate").value;
    StatusIndex = document.getElementById("divSelectStatus").selectedIndex.toString();
    CurrentPageIndex = "0";
    if (document.getElementById("divSelectPageIndex") != null) {
        CurrentPageIndex = document.getElementById("divSelectPageIndex").selectedIndex.toString();
    }

    RetValue = Portal.Vision.SearchContact.ServerSideSearchContact(RequireLookUp, ReturnCodeId, ReturnNameId, Name, Address, Phone, Agency, Applicant, Client, ThirdParty, GE, Legal, PJ, IP, ContactName, CountryIndex, ShortName, CustomerTypeIndex, SearchLevel, Email, fromDate, toDate, StatusIndex, CurrentPageIndex).value;
    if (RetValue.indexOf("ERROR") > -1) {
        alert(RetValue);
        return;
    }
    document.getElementById("divResult").innerHTML = RetValue;
    document.getElementById("divWaiting").innerHTML = "";



}

function SearchContactFunc() {
    document.getElementById("divWaiting").innerHTML = "Đọc dữ liệu từ máy chủ...";
    setTimeout("RealSearchContact()", 10);
}

function PdfFunc() {
    document.getElementById("divWaiting").innerHTML = "Đọc dữ liệu từ máy chủ...";
    setTimeout("RealPdfFunc()", 10);
}

function RealPdfFunc() {
    Name = document.getElementById("divSearchCustomerName").value;
    Address = document.getElementById("divSearchCustomerAddress").value;
    Email = document.getElementById("divSearchCustomerEmail").value;
    Phone = document.getElementById("divSearchCustomerPhone").value;
    Agency = document.getElementById("divCheckAgency").checked;
    Applicant = document.getElementById("divCheckApplicant").checked;
    Client = document.getElementById("divCheckClient").checked;
    ThirdParty = document.getElementById("divCheckThirdParty").checked;
    GE = document.getElementById("divCheckGE").checked;
    Legal = document.getElementById("divCheckLegal").checked;
    IP = document.getElementById("divCheckIP").checked;
    PJ = document.getElementById("divCheckPJ").checked;
    ContactName = document.getElementById("divSearchContactName").value;
    CountryIndex = document.getElementById("divSearchCountryIndex").value;
    ShortName = document.getElementById("divSearchShortName").value;
    CustomerTypeIndex = document.getElementById("divSearchCustomerTypeIndex").value;
    SearchLevel = document.getElementById("divSearchLevel").selectedIndex;
    fromDate = document.getElementById("divSearchCustomerFromDate").value;
    toDate = document.getElementById("divSearchCustomerToDate").value;
    RetValue = Portal.Vision.SearchCustomer.ServerSidePdfFunc(Name, Address, Phone, Agency, Applicant, Client, ThirdParty, GE, Legal, PJ, IP, ContactName, CountryIndex, ShortName, CustomerTypeIndex, SearchLevel, Email, fromDate, toDate).value;
    document.getElementById("divWaiting").innerHTML = "";
    if (RetValue.indexOf("ERROR") > -1) {
        alert(RetValue);
        return;
    }
    window.open(RetValue, "_blank");
}

function FullPdfFunc() {
    document.getElementById("divWaiting").innerHTML = "Đọc dữ liệu từ máy chủ...";
    setTimeout("RealFullPdfFunc()", 10);
}

function RealFullPdfFunc() {
    Name = document.getElementById("divSearchCustomerName").value;
    Address = document.getElementById("divSearchCustomerAddress").value;
    Email = document.getElementById("divSearchCustomerEmail").value;
    Phone = document.getElementById("divSearchCustomerPhone").value;
    Agency = document.getElementById("divCheckAgency").checked.toString();
    Applicant = document.getElementById("divCheckApplicant").checked.toString();
    Client = document.getElementById("divCheckClient").checked.toString();
    ThirdParty = document.getElementById("divCheckThirdParty").checked.toString();
    GE = document.getElementById("divCheckGE").checked.toString();
    Legal = document.getElementById("divCheckLegal").checked.toString();
    IP = document.getElementById("divCheckIP").checked.toString();
    PJ = document.getElementById("divCheckPJ").checked.toString();
    ContactName = document.getElementById("divSearchContactName").value;
    CountryIndex = document.getElementById("divSearchCountryIndex").value;
    ShortName = document.getElementById("divSearchShortName").value;
    CustomerTypeIndex = document.getElementById("divSearchCustomerTypeIndex").value.toString();
    SearchLevel = document.getElementById("divSearchLevel").selectedIndex.toString();
    fromDate = document.getElementById("divSearchCustomerFromDate").value;
    toDate = document.getElementById("divSearchCustomerToDate").value;
    document.getElementById("divWaiting").innerHTML = "";
    RetValue = Portal.Vision.SearchCustomer.ServerSidePdfFullFunc(Name, Address, Phone, Agency, Applicant, Client, ThirdParty, GE, Legal, PJ, IP, ContactName, CountryIndex, ShortName, CustomerTypeIndex, SearchLevel, Email, fromDate, toDate).value;

    if (RetValue.indexOf("ERROR") > -1) {
        alert(RetValue);
        return;
    }
    window.open(RetValue, "_blank");
}

function ShowContactListFunc(CustIndex) {
    HtmlAdded = Portal.Vision.SearchCustomer.ServerSideShowContactListFunc(CustIndex).value;
    if (HtmlAdded.indexOf("ERROR") > -1) {
        alert(HtmlAdded);
        return;
    }
    document.getElementById("divShowContact_" + CustIndex).innerHTML = HtmlAdded;
}

function ReturnValueFunc(RetCodeId, RetCode, RetCodeName, RetName) {
    window.opener.document.getElementById(RetCodeId).value = RetCode;
    window.opener.document.getElementById(RetCodeName).innerHTML = RetName;
    window.close();
}


function DeleteContact(Id) {
    if (confirm("Bạn có chắc chắn xóa contact này không?") == false) return;
    RetValue = Portal.Vision.SearchContact.ServerSideDeleteContact(Id).value;
    if (RetValue.indexOf("ERROR") > -1) {
        alert(RetValue);
        return;
    }
    alert("Contact đã được xóa. Nhấn Ok và F5 để cập nhật!");
}

function Add2CampainFunc(CampainId) {
    document.getElementById("divWaiting").innerHTML = "Đang xử lý....";
    setTimeout("RealAdd2CampainFunc('" + CampainId + "')", 10);
}


function RealAdd2CampainFunc(CampainId) {
    SelectIndex = document.getElementById("divSelectDeparmentForAdd").selectedIndex;
    DepartmentId = document.getElementById("divSelectDeparmentForAdd").options[SelectIndex].value;
    Name = document.getElementById("divSearchCustomerName").value;
    Address = document.getElementById("divSearchCustomerAddress").value;
    Email = document.getElementById("divSearchCustomerEmail").value;
    Phone = document.getElementById("divSearchCustomerPhone").value;
    Agency = document.getElementById("divCheckAgency").checked.toString(); ;
    Applicant = document.getElementById("divCheckApplicant").checked.toString(); ;
    Client = document.getElementById("divCheckClient").checked.toString(); ;
    ThirdParty = document.getElementById("divCheckThirdParty").checked.toString(); ;
    GE = document.getElementById("divCheckGE").checked.toString(); ;
    Legal = document.getElementById("divCheckLegal").checked.toString(); ;
    IP = document.getElementById("divCheckIP").checked.toString(); ;
    PJ = document.getElementById("divCheckPJ").checked.toString(); ;
    ContactName = document.getElementById("divSearchContactName").value;
    CountryIndex = document.getElementById("divSearchCountryIndex").value;
    ShortName = document.getElementById("divSearchShortName").value;
    CustomerTypeIndex = document.getElementById("divSearchCustomerTypeIndex").value;
    SearchLevel = document.getElementById("divSearchLevel").selectedIndex.toString(); ;
    fromDate = document.getElementById("divSearchCustomerFromDate").value;
    toDate = document.getElementById("divSearchCustomerToDate").value;

    RetValue = Portal.Vision.SearchContact.ServerSideAdd2CampainFunc(CampainId, DepartmentId, Name, Address, Phone, Agency, Applicant, Client, ThirdParty, GE, Legal, PJ, IP, ContactName, CountryIndex, ShortName, CustomerTypeIndex, SearchLevel, Email, fromDate, toDate).value;
    document.getElementById("divWaiting").innerHTML = "";
    if (RetValue.indexOf("ERROR") > -1) {
        alert(RetValue);
        return;
    }
    alert("Contacts đã được đưa vào chiến dịch");
}